<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<html>
<head>
<title>页面</title>
<style type="text/css">
/*top*/
body{margin:0 auto;padding:0 auto;text-align: center;width:980px;}

span{font-size:13px;}

table{border:1px dashed white;background: white;}

.content{float: right;top: -180px;position: relative;}

.info{margin-left: 800px;}

.div_content table{border:1px solid white;background: white;}/*/////////////////////////////////////////////////////*/

td{border: 1px dashed gray;}

ul, li { list-style:none;}

a { text-decoration:none;}

.nav {margin-top: -10px;margin-left: 50px;}/*////////////////////////////////////////////////*/

.jieshao{float: left;position: relative;left: 200px;}

.nav ul li { float:left;}

.nav ul li a { width:120px; height:40px; text-align:center; line-height:40px; display:block; border-right:2px solid #ccc; background:#eee; color:#666;}

.nav ul li a:hover{ color:#f00;background: #000000;}

.nav ul li ul { position:absolute; display:none;}

.nav ul li ul li { float:none;}

.nav ul li ul li a { border-right:none; border-top:1px dotted #ccc; background:#f5f5f5;}

.nav ul li:hover ul{ display:block; }

.top{margin: 5px auto 0px auto;padding: 0px;width:980px;height:78px;text-align: left;}

.logo{margin-right: 900px;}

.banner{width: 307px;height: 61px;float:left;margin-top: -10px;}

.options{float: right;margin: -20px;}

.home,.shu,.fav{float: leftmargin: 0 16px;padding:0 0 auto auto;display: inline;padding: 0px 0px;margin-right: 20px;}

.home a,.shu a,.fav a{color: #9b9b9b;float: left;margin-left: 15px;margin-top: -10px;}
/*top*/
.content{margin: 80px 0px ; }

h1{ background:black; font-size:14px; height:35px; line-height:35px; padding-right:900px; color:white;margin-top: 80px;}

.tuichu{position: relative;left: 450px;color:gray;}

#Methods1{ width:900px;height:110px; background:#ccc;}

#Methods1 dl{margin:0px 10px 0 10px; float:left; border:1px solid gray;}

#Methods1 dt{width:180px; margin:10px; height:90px; background:#FFF;}

#Methods1 dd{width:180px; margin:0 0 10px 10px; height:20px; line-height:30px; background:#FFFFFF; text-align:center;}

.td1{margin-top: 0px;}

.td2{margin-top: 0px;}

.td3{margin-top: 0px;}

.td4{margin-top: 0px;}

.td1 .td1_content{float: left;}

.tips{margin-top: 0px;margin-right: 170px;}

.tips span{color:gray;font-size: 13px;}

.tips ul{margin-right: 50px;}

hr{border:1px dashed gray;}

.qingchu{position: relative;left: 200px;}

.xiaoxi{text-align: left;}
/*nav*/
</style>

</head>
  <body>
    <%@ include file="dengluPublic.jsp" %>
 <%@ include file="daohangPublic.jsp"%>
  <%!
	    String id;
	    String publisher;
	    String idAfter;
	    String cno;
	    String fno;
	    String fno9;
	    String cno1;
	    String xiaoxi1;
	    String xiaoxi2;
	    ResultSet rs2;
	    ResultSet rs3;	 
	    ResultSet rs4;
	    ResultSet rs5;   
	    %>
	       <%
	    id=request.getParameter("id");
	    System.out.println("聊天页接收的id"+id);
	     %>
	    <% 
		String driverClass="com.mysql.jdbc.Driver";
	    String url="jdbc:mysql://localhost:3306/vote?useSSL=false";
	    String user="root";
	    String password="womenilu2580";
	    Class.forName(driverClass);	   
	    Connection conn=DriverManager.getConnection(url,user,password);
	    Statement stat=conn.createStatement();	 
	    String sql="select publisher,cno from science where id="+id+"";
	    ResultSet rs=stat.executeQuery(sql);
	    while(rs.next()){
	    publisher=rs.getString("publisher");
	    System.out.println("pub"+publisher);
	    cno1=rs.getString("cno");	
	    }
	    System.out.println("这里的id是shi"+id+cno1);
	     
	    Class.forName(driverClass);	   
	    Connection conn9=DriverManager.getConnection(url,user,password);
	    Statement stat9=conn9.createStatement();	 
	    String sql9="select cno from t_customer where cname='"+customer.getCname()+"'";	    	   	    
	    ResultSet rs9=stat9.executeQuery(sql9);
	    while(rs9.next())
	    {
	    	fno9=rs9.getString("cno");
	    	
	    }  
		    String driverClass1="com.mysql.jdbc.Driver";
		    String url1="jdbc:mysql://localhost:3306/vote?useSSL=false";
		    String user1="root";
		    String password1="womenilu2580";
		    Class.forName(driverClass1);  
			Connection conn1=DriverManager.getConnection(url,user,password);	    
		    Statement stat1=conn1.createStatement();	 
		    String sql1="select * from friend where cname='"+customer.getCname()+"'and friend='"+publisher+"'";
		    ResultSet rs1=stat.executeQuery(sql1);	    
		    //rs1.previous();
		    if(!customer.getCname().equals(publisher))
		    {		    	
			    if(rs1.next())//查询结果有数据
			    {
			    	rs1.previous();
			    	while(rs1.next())//根据查询名字查询序号，方便查询消息
			    	{
			    		cno=rs1.getString("cno");
			    		fno=rs1.getString("fno");
			    		System.out.println("我查询到的数据时"+cno+","+fno);			    		
					}			    			
					Class.forName(driverClass1);  
					Connection conn2=DriverManager.getConnection(url,user,password);	    
				    Statement stat2=conn2.createStatement();	 
				    String sql2="select xiaoxi,cno from xiaoxi where cno='"+cno+"'and fno='"+fno+"'";
				    rs2=stat2.executeQuery(sql2);	 
				    System.out.println(">>>>>"+cno+fno);
				    
				    Class.forName(driverClass1); 
				    Connection conn3=DriverManager.getConnection(url,user,password);	    
				    Statement stat3=conn3.createStatement();	 
				    String sql3="select xiaoxi,cno from xiaoxi where cno='"+fno+"'and fno='"+cno+"'";
				    rs3=stat3.executeQuery(sql3);
				    System.out.println(">>>>>"+fno+cno);			    				   				    
			    	System.out.println("有数据");//就不加
			    	System.out.println("发布者"+publisher);
			    	%>
			    	
		<h1><font>与<%=publisher %>聊天</font></h1>		   
		<div id="Methods1">
			<table width="980px">			
		<tr>
			<td width="225px">
				<div class="td1">
					<dl>
				    	<dt><a href="customerPage.jsp?cno=<%=cno1%>"><img src="img/logo.jpg" width="180px" height="90px" /></a></dt>
				    	<dd>-用户-：<a href="customerPage.jsp?cno=<%=cno1%>"> <%=publisher %></a><sup>好友</sup></dd>
				
				    </dl>
				    
			    </div>
			    
			    <div class="div_content">			    
			     <%while(rs3.next())
				    {System.out.println(">>>>>"+cno+fno+">>>>>>");				    	
				    	xiaoxi2=rs3.getString("xiaoxi");				    				    	
				    	System.out.println("消息是2"+xiaoxi2);		
		   
				     %>
			    <div class="xiaoxi"><%=publisher%>说：<%=xiaoxi2 %><hr/></div>
			    <%} %>	
			    <%while(rs2.next())
				    {
				    	xiaoxi1=rs2.getString("xiaoxi");				    	
				    	System.out.println("消息是1"+xiaoxi1);
				     %>
			    <div class="xiaoxi"><%=customer.getCname()%>说:<%=xiaoxi1 %><hr/></div>
			    <%} %>				   	     
		       
		       <table width="980px">
		       <tr>
		
		       <td>
			      <form action="chatNewsReciever.jsp?cno=<%=cno%>&id=<%=id %>&fno=<%=fno %>" method="post">
			     输入聊天信息：<input name="msg" type="text" size="40"/>
			     <input type="submit" value="发送"/>
			     <a href="deleteChatMessage.jsp?cno=<%=cno%>&fno=<%=fno%>"><font class="qingchu">清除聊天记录</font></a><br />
			     </form>
		     </td>
		     </tr>
		     </table>     
				</div> 
			    		    
			</td>
		</tr>
		</table>
				    	<%
				    	 		}else{//查询结果为空
			    	 		%>
		    	<%System.out.println("没数据");//加	     	        		    	
		    %> 	    
	   <h1><font>与<%=publisher %>聊天</font></h1>	   
	<div id="Methods1">
		<table width="980px">
		
	<tr>
		<td width="225px">
			<div class="td1">
				<dl>
			    	<dt><a href="customerPage.jsp?cno=<%=cno1%>"><img src="img/logo.jpg" width="180px" height="90px" /></a></dt>
			    	<dd>-用户-：<a href="customerPage.jsp?cno=<%=cno1%>"><%=publisher %></a>
			    	<a href="addFriend.jsp?cno=<%=cno1%>&id=<%=id%>"><sup>添加好友</sup></a></dd>
			
			    </dl>
		    </div>	 
		    <div class="div_content">		    
		    
		          <%
		          	Class.forName(driverClass1); 
				    Connection conn4=DriverManager.getConnection(url,user,password);	    
				    Statement stat4=conn4.createStatement();	 
				    String sql4="select xiaoxi,cno from xiaoxi where cno='"+cno1+"'and fno='"+fno9+"'";
				    rs4=stat4.executeQuery(sql4);
		          while(rs4.next())
				    {System.out.println(">>>>>"+cno+fno+">>>>>>");				    	
				    	xiaoxi2=rs4.getString("xiaoxi");				    	
				    	System.out.println("消息是2"+xiaoxi2);		
		   
				     %>
			    <div class="xiaoxi"><%=publisher%>说：<%=xiaoxi2 %><hr/></div>
			    <%} %>	
			    <%
			    	Class.forName(driverClass1); 
				    Connection conn5=DriverManager.getConnection(url,user,password);	    
				    Statement stat5=conn5.createStatement();	 
				    String sql5="select xiaoxi,cno from xiaoxi where cno='"+fno9+"'and fno='"+cno1+"'";
				    rs5=stat5.executeQuery(sql5);
			    while(rs5.next())
				    {
				    	xiaoxi1=rs5.getString("xiaoxi");				    	
				    	System.out.println("消息是1"+xiaoxi1);
				     %>
			    <div class="xiaoxi"><%=customer.getCname()%>说:<%=xiaoxi1 %><hr/></div>
			    <%} %>		 	   
	       
	       <table width="980px">
	       <tr>
	
	       <td>
			      <form action="chatNewsReciever.jsp?cno=<%=fno9%>&id=<%=id %>&fno=<%=cno1 %>" method="post">
				     输入聊天信息：<input name="msg" type="text" size="40"/>
			     <input type="submit" value="发送"/>
			     <a href="deleteChatMessage.jsp?cno=<%=cno1%>&fno=<%=fno9%>"><font class="qingchu">清除聊天记录</font></a><br />
			     </form>
			</td>
	     </tr>
	     </table>     
			</div> 
		    		    
		</td>
	</tr>
	</table>
	<%
	
	}
	}else{		
	 %>
	  <%} %>
<hr/>
本站由Dany团队搭建，欢迎有兴趣的朋友加入我们，一起建造更优质的平台
<br/>
作者联系方式：1029046433(qq)
</div>
  </body>
</html>
